<?php

namespace App\Admin\Controllers;

use App\Services\HardwareMoveRecordService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 动线记录
 *
 * @property HardwareMoveRecordService $service
 */
class HardwareMoveRecordController extends AdminController
{
	protected string $serviceName = HardwareMoveRecordService::class;

	public function index()
	{
		if ($this->actionOfGetData()) {
			$hardware_id = request()->input('hardware_id');
			if ($hardware_id) {
				return $this->service->getByHardwareId($hardware_id);
			}
			return $this->response()->success($this->service->list());
		}

		return $this->response()->success($this->list());
	}

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('add_time', '添加时间'),
				amis()->TableColumn('after_location', '动后位置')->sortable(),
				amis()->TableColumn('editor_uid', '编辑人UID')->sortable(),
				amis()->TableColumn('hardware_id', '硬件ID'),
				amis()->TableColumn('move_remark', '动线记录备注'),
				amis()->TableColumn('move_time', '动线时间'),
				amis()->TableColumn('operator_uid', '操作人UID')->sortable(),
				amis()->TableColumn('previous_location', '动前位置')->sortable(),
				amis()->TableColumn('sn_code', '硬件SN码'),
				amis()->TableColumn('soft_delete', '软删除标识（0未删除，1已删除）'),
				amis()->TableColumn('update_time', '更新时间'),
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				amis()->TableColumn('updated_at', admin_trans('admin.updated_at'))->type('datetime')->sortable(),
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('add_time', '添加时间'),
			amis()->TextControl('after_location', '动后位置'),
			amis()->TextControl('editor_uid', '编辑人UID'),
			amis()->TextControl('hardware_id', '硬件ID'),
			amis()->TextControl('move_remark', '动线记录备注'),
			amis()->TextControl('move_time', '动线时间'),
			amis()->TextControl('operator_uid', '操作人UID'),
			amis()->TextControl('previous_location', '动前位置'),
			amis()->TextControl('sn_code', '硬件SN码'),
			amis()->TextControl('soft_delete', '软删除标识（0未删除，1已删除）'),
			amis()->TextControl('update_time', '更新时间'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('add_time', '添加时间')->static(),
			amis()->TextControl('after_location', '动后位置')->static(),
			amis()->TextControl('editor_uid', '编辑人UID')->static(),
			amis()->TextControl('hardware_id', '硬件ID')->static(),
			amis()->TextControl('move_remark', '动线记录备注')->static(),
			amis()->TextControl('move_time', '动线时间')->static(),
			amis()->TextControl('operator_uid', '操作人UID')->static(),
			amis()->TextControl('previous_location', '动前位置')->static(),
			amis()->TextControl('sn_code', '硬件SN码')->static(),
			amis()->TextControl('soft_delete', '软删除标识（0未删除，1已删除）')->static(),
			amis()->TextControl('update_time', '更新时间')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}
